package com.example.security_demo.filter;

import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 通过获取请求头中token来进行认证，查看其是否具有权限
 *
 * @author zzh
 * @date 2022/5/21
 * @since 1.0
 */
public class JwtTokenAuthenticationFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

        String token = request.getHeader("token");
        if (token == null) {
            throw new UsernameNotFoundException("权限不足");
        }
    }
}
